procedure Display_the_PICT (var pictRect: Rect; thePicture: PicHandle; var theLeftPicture: PicHandle; var theRightPicture: PicHandle; var theEscPicture: PicHandle; var prevDrawRect: Rect);
var
drawRect: Rect; { Where we draw the PICT }
pictHeight, pictWidth: Integer; { used in calculating screen co-ordinates}
insetHeight, insetWidth: Integer;{ used in calculating screen co-ordinates}
{ Note: the above 4 variables aren't strictly}
{ necessary, but they make the code }
{ easier to read}
begin
{ Blank the screen}
drawRect := screenBits.bounds;
ClipRect(drawRect);
ForeColor(blackColor);
PaintRect(prevDrawRect);
{ get PICT dimensions (already loaded by "Get_Next_PICT")}
pictHeight := pictRect.bottom - pictRect.top;
pictWidth := pictRect.right - pictRect.left;
{ calculate the insets required to centralise it on the monitor}
insetWidth := (gScreenBounds.right - pictWidth) div 2;
insetHeight := (gScreenBounds.bottom - pictHeight) div 2;
{ calculate the drawing frame co-ordinates}
drawRect.top := insetHeight;
drawRect.left := insetWidth;
drawRect.bottom := insetHeight + pictHeight;
drawRect.right := insetWidth + pictWidth;
{ set the clipping region in the window and draw the PICT}
ClipRect(drawRect);
DrawPicture(thePicture, drawRect);
{Return the new position so it will be erased properly}
function Check_for_Events (pictID: Integer; var theEvent: EventRecord; mouseRegion: RgnHandle; var pictRect: Rect; thePicture: PicHandle; theLeftPicture: PicHandle; theRightPicture: PicHandle; theEscPicture: PicHandle; var done: Boolean; var prevDrawRect: Rect): Integer;
const
kEsc = Char(27);
kLeftArrow = Char(28);
kRightArrow = Char(29);
kUpArrow = Char(30);
kDownArrow = Char(31);
var
buttonNotHit: Boolean; { unless a button is hit that we can do something about}
{ there's nothing to be done.}
procedure Right;
begin
pictID := pictID + 1; { try for the next PICT }
if (Get_Next_PICT(pictID, pictRect, thePicture)) then { this call locks thePicture handle}
{ if successful}
begin
buttonNotHit := false;
HUnlock(Handle(thePicture));
ReleaseResource(Handle(thePicture));
end
else
begin
pictID := pictID - 1;
SysBeep(1); {Hit the edge! Beep!}
end; { put it back to where it was - nothing to do}
end;
procedure Left;
begin
if (pictID > 128) then
begin
pictID := pictID - 1;
buttonNotHit := false;
end
else
SysBeep(1); {Hit the edge! Beep!}
end;
procedure Esc;
begin
done := true;
Exit(Check_for_Events);
end; { User wants to Quit}
begin
buttonNotHit := true;
Check_for_Events := pictID;
if WaitNextEvent(everyEvent, theEvent, 10, mouseRegion) then
;
if theEvent.what = keyDown then
begin
case Char(BitAnd(theEvent.message, charCodeMask)) of
'.': {Period: either right half of the 'comma and period' pair, or command-period,}
if BitAnd(theEvent.modifiers, cmdKey) <> 0 then
Esc
else
Right;
kLeftArrow, '<', ',', '-':
Left;
kRightArrow, '>', '+':
Right;
kEsc:
Esc;
'q', 'Q': {Q is valid only withthe command key.}
if BitAnd(theEvent.modifiers, cmdKey) <> 0 then
Esc;
otherwise
end; {case}
end; {keyDown}
if theEvent.what = mouseDown then
begin
{ OK: the user's clicked the mouse - let's find out if a button was hit}
{ Esc Button hit}
if (theEvent.where.v >= 20) and (theEvent.where.v <= 52) and (theEvent.where.h >= 0) and (theEvent.where.h <= 32) then
Esc;
{ Left Button hit}
if (theEvent.where.v >= gScreenBounds.bottom - 32) and (theEvent.where.v <= gScreenBounds.bottom) and (theEvent.where.h >= 0) and (theEvent.where.h < 32) then
Left;
{ Right Button hit}
if (theEvent.where.v >= gScreenBounds.bottom - 32) and (theEvent.where.v <= gScreenBounds.bottom) and (theEvent.where.h >= gScreenBounds.right - 32) and (theEvent.where.h <= gScreenBounds.right) then
Right;
end; {mouseDown}
Check_for_Events := pictID;
if not buttonNotHit then
if (Get_Next_PICT(pictID, pictRect, thePicture)) then{though this should be sure to succeed by now!}